<?php

namespace app\admin\validate;

use think\Validate;

class Appointment extends Validate
{
    protected $failException = true;

    /**
     * 验证规则
     */
    protected $rule = [
        'appointment_date' => 'require',
        'start_time' => 'require',
        // 'end_time' => 'require|checkTime',
        // 'room_id' => 'require',
        // 'medical_staff_id' => 'require',
        'store_id' => 'require',
    ];

    /**
     * 提示消息
     */
    protected $message = [
        'appointment_date.require' => '预约日期不能为空',
        'start_time.require' => '开始时间不能为空',
        // 'end_time.require' => '结束时间不能为空',
        // 'end_time.checkTime' => '结束时间必须大于开始时间',
        'room_id.require' => '房间不能为空',
        'medical_staff_id.require' => '医人员不能为空',
        'store_id.require' => '请选择一个门店',
    ];

    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['appointment_date', 'start_time', 'room_id','medical_staff_id','store_id'],
        'edit' => ['appointment_date', 'start_time', 'room_id','medical_staff_id','store_id'],
    ];

    // 验证结束时间必须大于开始时间
    protected function checkTime($value, $rule, $data)
    {
        $start = strtotime($data['appointment_date'] . ' ' . $data['start_time']);
        $end = strtotime($data['appointment_date'] . ' ' . $value);
        return $end > $start;
    }
}
